package threaddemo;
class Counter {
    public static int count = 0;
    public synchronized void increment() {
        count++;
    }

    public void incrment() {
        synchronized (this) {
            count++;
        }
    }

    public static void incrementStatic() {
        synchronized (Counter.class) {
            count++;
        }
    }

    synchronized public static void increamt3 () {
        count++;
    }
}
public class demo4 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                counter.increment();
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                counter.increment();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(counter.count);
    }
}
